﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using ttbit.core;

namespace ttbit.core
{
    public class Font
    {
        public string name;
        public int size;
        public Texture texture;
        public Dictionary<char, Sprite> sprites = new Dictionary<char, Sprite>();
        public int GetCharWidth(char c)
        {
            if (c > 0xff)
            {
                return size;
            }
            else if (sprites.TryGetValue(c, out Sprite s))
            {
                //AscII字符的宽度是其UV值+1,等下,我为啥这么卑微?直接字体加载时处理完不就好了.
                return s.Width;
            }
            else
            {
                return size / 2;
            }
        }
        public int GetStringWidth(string str)
        {
            var wa = 0;
            foreach (var t in str)
            {

                var w = GetCharWidth(t);
                wa += w;
            }
            return wa;
        }
    }
}
